<?php

namespace app\model;
use GuzzleHttp\Psr7\Racoojng;
use think\Model;

class Address extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'address';

    public static function getthefare($address_id, $technicalId)
    {
        $shipping = Address::find($address_id);
        $technical =  Technical::getInfo($technicalId);
        $from['longitude'] = $technical['longitude'];
        $from['latitude'] = $technical['latitude'];
        $to['longitude'] = $shipping['longitude'];
        $to['latitude'] = $shipping['latitude'];
        if ($from['longitude'] && $from['latitude'] && $to['longitude'] && $to['latitude']) {
            $data["distance"] = Racoojng::get_distance($from, $to);
            if ($data["distance"]) {
                $Configthefare = Config::getconfig('thefare');
                $data["thefare"] = round(($data["distance"] * $Configthefare['mileageprice']), 2);
            }
        }
        return $data;
    }
}
